# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=alembic
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.5.4
pkgrel=2
pkgdesc="Lightweight database migration tool for usage with SQLAlchemy (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://bitbucket.org/zzzeek/alembic'
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-mako"
         "${MINGW_PACKAGE_PREFIX}-python-sqlalchemy"
         "${MINGW_PACKAGE_PREFIX}-python-editor"
         "${MINGW_PACKAGE_PREFIX}-python-dateutil")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${MINGW_PACKAGE_PREFIX}-python-mock")
options=('staticlibs' 'strip' '!debug')
source=(https://pypi.org/packages/source/a/alembic/alembic-${pkgver}.tar.gz)
sha512sums=('190f8fe96f18541fd62802e026e93c332f6046618cb89d4f9a6b478505742671d363de1161feeccd8873036a458743165080b5a0e2e55e1d0dd81e617c8cd4ad')

prepare() {
  cd "${srcdir}"
  rm -rf "python-build-${CARCH}" | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

build() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/py.test || warning "Test failed"
}

package() {
  cd "${srcdir}/python-build-${CARCH}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"

 for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    sed -e '1 { s/^#!.*$// }' -i ${_f}
  done
}
